package fnord.jovian.tango;

import java.util.Vector;

import fnord.illuminati.card.GroupCard;
import fnord.jovian.TheBoard;
import fnord.jovian.tango.TheAssemblyLayout.TheAssemblyOrientation;

public class TheMoneyTransferMenu extends TheMenu {
	
	private TheSlider _slider;
	private GroupCard _attacker, _defender;

	public TheMoneyTransferMenu(TheBoard board) {
		super(300, 300, board);
		_mask = null;
		TheAssemblyLayout layout = new TheAssemblyLayout(TheAssemblyOrientation.VERTICAL);
		setTheLayout(layout);	
	}
	
	public void setTransfer(TheCard from, TheCard to) {
		_objects = new Vector<TheObject>();
		this.addComponent(new TheText("From " + from.getCard().getName() + " to " + to.getCard().getName(), 8, 200, 30, true, true));
		_slider = new TheSlider(from.getCard().getMoney(),200);
		this.addComponent(_slider);
		this.addComponent(new TheButton("Transfer Money", 200, 30, new TheTransferListener()));
		this.addComponent(new TheButton("Cancel Transfer", 200, 30, new TheCancelListener()));
	}
	
	public void setMoney(GroupCard from, GroupCard to) {
		_attacker = from;
		_defender = to;
		_objects = new Vector<TheObject>();
		this.addComponent(new TheText(from.getName() + " attacked " + to.getName(), 8, 200, 30, true, true));
		_slider = new TheSlider(from.getMoney(),200);
		this.addComponent(_slider);
		this.addComponent(new TheButton("Spend on Attacker", 200, 30, new TheSpendListener(true)));
		this.addComponent(new TheButton("Spend on Defender", 200, 30, new TheSpendListener(false)));
		this.addComponent(new TheButton("Don't Spend Money", 200, 30, new TheSpendlessListener()));
	}
	
	private class TheCancelListener implements TheListener {
        public void doAction() {
			_board.cancelAction();
        }
	}
	
	private class TheSpendlessListener implements TheListener {
        public void doAction() {
			_board.spendMoney(0, _defender);
        }
	}
	
	private class TheSpendListener implements TheListener {
		private boolean _attack;
		
		public TheSpendListener(boolean attack) {
			_attack = attack;
		}
        public void doAction() {
        	if (_attack)
    			_board.spendMoney((int)_slider.getValue(), _attacker);
        	else
    			_board.spendMoney((int)_slider.getValue(), _defender);
        }
	}

	private class TheTransferListener implements TheListener {
        public void doAction() {
			_board.transferMoney((int)_slider.getValue());
        }
	}

}
